package homework;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class SaveToSet {
	
	public Set<Customer> scanFile(String filePath) throws IOException{
		String[] rs={""};
		String string=null;
		Set<Customer> set = new TreeSet<Customer>();
		try {
			File file=new File(filePath);
			InputStreamReader read=new InputStreamReader(new FileInputStream(file));
			BufferedReader bufferedReader = new BufferedReader(read);
			InfFilter iFilter=new InfFilter();
			string=bufferedReader.readLine();
			while (string!=null) {
				rs=string.split("\\s+");
				Customer c=new Customer(iFilter.getId(rs[0]),iFilter.getName(rs[1]),iFilter.getMail(rs[2]),
						iFilter.getSex(rs[3]),iFilter.getBirthday(rs[4]));
				set.add(c);
				string=bufferedReader.readLine();
			}	
		} catch (FileNotFoundException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return set;
		
	}
	


}
